import { Directive, HostListener, Input } from '@angular/core';

@Directive({
  selector: '[libCopyToClipboard]',
  standalone: true
})
export class CopyToClipboardDirective {
  @Input() libCopyToClipboard: string = '';

  constructor() { }

  @HostListener('click') onClick() {
    const textarea = document.createElement('textarea');
    textarea.style.position = 'fixed';  // Avoid scrolling to bottom
    textarea.style.opacity = '0';
    textarea.value = this.libCopyToClipboard || '';
    document.body.appendChild(textarea);
    textarea.select();
    document.execCommand('copy');
    document.body.removeChild(textarea);
  }

}

//<button [libCopyToClipboard]="'Text to be copied!'">Click to Copy</button>


